public class defaultAdrsList implements AdrsList {

	private int pathNum;
	private Adrs[][] path;
	private int[] adrsNum;
	private int[] firstAdrs;
	private int listLength=10;

	public defaultAdrsList(AdrsList dal){
		this.pathNum=dal.getPathNum();
		this.setAdrsNumList(dal.getAdrsNumList());
		this.setPath(dal.getPath());
		this.setFirstNumList(dal.getFirstNumList());
	}
	public defaultAdrsList(int pathNum) {
		this.pathNum = pathNum;
		this.adrsNum = new int[pathNum];
		this.firstAdrs = new int[pathNum];
		this.path=new Adrs[pathNum][10];
		this.path = new defaultAdrs[pathNum][10];
		for (int i = 0; i < pathNum; i++) {
			this.adrsNum[i] = 0;
			this.firstAdrs[i] = 0;
		}
	}

	public int getListLength(){
		return this.listLength;
	}
	public void setListLength(int l){
		this.listLength=l;
	}

	@Override
	public void addAdrs(Adrs a, int path) {
		//System.out.println(a);
		this.path[path][this.adrsNum[path]] = a;
		this.adrsNum[path]++;
	}

	@Override
	public void addAdrs(int x, int y, int path) {
		this.addAdrs(new defaultAdrs(x, y), path);

	}

	public Adrs getFirstAdrs(int pathNum) {
		Adrs temp = this.path[pathNum][this.firstAdrs[pathNum]];
		this.firstAdrs[pathNum]++;
		this.adrsNum[pathNum]--;

		return temp;
	}

	@Override
	public Adrs lookFirstAdrs(int pathNum) {
		// TODO Auto-generated method stub
		if (pathNum >= this.pathNum)
			return null;
		else if (this.path[pathNum][this.firstAdrs[pathNum]] != null)
			return new defaultAdrs(this.path[pathNum][this.firstAdrs[pathNum]]);
		else
			return null;
	}

	@Override
	public int getAdrsNum(int pathNum) {
		// TODO Auto-generated method stub
		return this.adrsNum[pathNum];
	}

	@Override
	public int getPathNum() {
		// TODO Auto-generated method stub
		return this.pathNum;
	}

	@Override
	public boolean hasAdrs(Adrs adrs) {
		for (int i = 0; i < this.pathNum; i++) {
			for (int j = 0; j < this.getAdrsNum(i); j++) {
				if (this.path[i][j].equals(adrs)) {
					return true;
				}
			}
		}
		return false;
	}
	public Adrs[][] getPath(){
		return this.path;
	}
	public void setPath(Adrs[][] a){
		this.path=a;
	}
	public int[] getAdrsNumList(){
		return this.adrsNum;
	}
	public void setAdrsNumList(int[] a){
		this.adrsNum=new int[a.length];
		for(int i=0;i<a.length;i++){
			this.adrsNum[i]=a[i];
		}
	}
	public int[] getFirstNumList(){
		return this.firstAdrs;
	}
	public void setFirstNumList(int[] a){
		this.firstAdrs=new int[a.length];
		for(int i=0;i<a.length;i++){
			this.firstAdrs[i]=a[i];
		}
		
	}

}
